package strategy;

import java.util.Arrays;

/**
 * @ClassName : Sort
 * @Description : 排序
 * @Author : gyh
 * @Date: 2021-09-14 00:15
 */
public class Sort {

    public static void bubbleSort(Comparable[] arr){
        for (int i = arr.length; i > 0; i--) {      //外层循环移动游标
            for(int j = 0; j < i && (j+1) < i; j++){    //内层循环遍历游标及之后(或之前)的元素
                if(arr[j].compareTo(arr[j + 1])>0){
                    Comparable temp = arr[j];
                    arr[j] = arr[j+1];
                    arr[j+1] = temp;
                    System.out.println("Sorting: " + Arrays.toString(arr));
                }
            }
        }
    }
}
